#include "listnode.h"
/*
https://leetcode.cn/problems/swap-nodes-in-pairs
*/
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* swapPairs(struct ListNode* head)
{
    struct ListNode* pre = malloc(sizeof(struct ListNode));
    pre->next = head;
    struct ListNode* temp = pre;

    while (temp->next && temp->next->next)
    {
        struct ListNode* start = temp->next;
        struct ListNode* end = temp->next->next;
        start->next = end->next;
        end->next = start;
        temp->next = end;
        temp = start;
    }
    return pre->next;
}
